package cate.game.role.farm.island.po;

import cate.common.table.d.GD;
import cate.game.play.fighter.HeroFighter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;

@NoteClass(value = "冒险英雄状态")
public class HeroState{
    @NoteField(value = "英雄唯一id")
    public String heroUid;

    @NoteField(value = "血量比例")
    public double hpRate;

    public void update(HeroFighter fighter) {
        this.heroUid = fighter.uid;
        hpRate = fighter.attr.total().hpCurRate()/ GD.W_10000_0;
    }

    public double getHpRate() {
        return hpRate;
    }

    public void heal(double healRate) {
        if (isDead()) {
            return;
        }
        hpRate += healRate;
        if (hpRate >= 1) {
            hpRate = 1;
        }
    }

    @JsonIgnore
    // 是否死亡
    public boolean isDead() {
        return hpRate <= 0;
    }

    @JsonIgnore
    // 是否满血
    public boolean isFull() {
        return hpRate >= 1;
    }

    public HeroState copy() {
        HeroState state = new HeroState();
        state.heroUid = heroUid;
        state.hpRate = hpRate;
        return state;
    }
}
